﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Marbles.Core.Settings;

namespace Marbles.Core.Connectors
{
    public class DataConnection : IDataConnection
    {

        public static DateTime MinimumDateTime { get { return new DateTime(1980, 1, 1, 0, 0, 0); } }

        public string ProviderName { get { return provider.ProviderName; } }

        private IDataConnection provider = null;

        public DataConnection()
        {
            provider = CreateInstance();
        }

        internal static IDataConnection CreateInstance()
        {
            return CreateInstance(SettingsManager.Connection.ProviderName);
        }

        internal static IDataConnection CreateInstance(string providername)
        {

            switch (providername.ToLower())
            {
                case "sqlserver":
                    return new SqlDataConnection();
            }

            return null;
        }

        public System.Data.DataTable FetchDataTable(Command Command)
        {
            return provider.FetchDataTable(Command);
        }

        public System.Data.DataSet FetchDataSet(Command Command)
        {
            return provider.FetchDataSet(Command);
        }

        public int ExecuteCommand(Command Command)
        {
            return provider.ExecuteCommand(Command);
        }

        public System.Data.IDbCommand CreateSqlCommand(System.Data.IDbConnection Connection, Command Command)
        {
            return provider.CreateSqlCommand(Connection, Command);
        }

        public bool Ping()
        {
            return provider.Ping();
        }

        public string BuildConnectionString(string Host, string Username, string Password, string Database)
        {
            return provider.BuildConnectionString(Host, Username, Password, Database);
        }

    }
}